package com.guet.niit.User.service;

import com.guet.niit.User.dao.UserDao;
import com.guet.niit.User.dao.UserDaoImpl;
import com.guet.niit.User.pojo.Account;
import com.guet.niit.User.pojo.ChargingRecord;
import com.guet.niit.User.pojo.UserCar;
import javafx.scene.control.Alert;

import java.util.ArrayList;

//任务：调用UserDao接口里的方法
public class UserService {
    public ArrayList<UserCar> ReturnCarResult(Long UserId){
//        long UserId=852334574041313280L;
        UserDaoImpl userDao = new UserDaoImpl();
        ArrayList<UserCar> plate = userDao.FindAllByUserId(UserId);
//        System.out.println(plate);
        return plate;
    }
    public Double ReturnBalace(Long UserId){
        UserDaoImpl userDao = new UserDaoImpl();
//        Double Balance = userDao.FindBalanceByUserId(852334574041313280L);
        Double Balance = userDao.FindBalanceByUserId(UserId);
        return Balance;
    }
    public void Add(Account account,Double menoy,Double ban){
        double newBlance = ban + menoy;
//        问题出在account.getBalance()
        System.out.println(account.getBalance());
        System.out.println("service"+menoy);
        Account newAccount = new Account();
        newAccount.setBalance(newBlance);
        UserDaoImpl userDao = new UserDaoImpl();
//        需要获取当前登录的用户id，传给方法
//        测试先随便用个
        Long id=852334574041313280L;
        userDao.UpdateBalanceByUserId(id,newBlance);
    }

    //更新用户余额
    public void UpdateBalanceByUserId(Long userId,Double newBalance){
        UserDao userDao = new UserDaoImpl();
        int status = userDao.UpdateBalanceByUserId(userId, newBalance);
        if (status>0){
            Alert alert = new Alert(Alert.AlertType.INFORMATION);
            alert.setHeaderText(null);
            alert.setContentText("充值成功！");
            alert.showAndWait();
        }
    }

    public ArrayList<ChargingRecord> FindChargingRecordByUserId(Long UserId) {
//        long UserId = 852334574041313280L;
        UserDaoImpl userDao = new UserDaoImpl();
        ArrayList<ChargingRecord> Record=userDao.FindChargingRecordByUserId(UserId);
        return Record;
    }
    public void updateBan(Double bace){
        UserDaoImpl userDao = new UserDaoImpl();
        userDao.UpdateBalanceByUserId(852334574041313280L,bace);
    }
    public String returnPassword(Long UserId){
//        long UserId = 852334574041313280L;
        UserDaoImpl userDao = new UserDaoImpl();
        String password= userDao.findPasswordByUserId(UserId);
        return password;
    }
    public void updatePassword(Long UserId,String password){
        UserDaoImpl userDao = new UserDaoImpl();
//        userDao.updatePasswordByUserId(852334574041313280L,password);
//        userDao.updatePasswordByUserId(UserId,password);
        int status = userDao.updatePasswordByUserId(UserId, password);
        if (status>0){
            Alert alert = new Alert(Alert.AlertType.INFORMATION);
            alert.setHeaderText(null);
            alert.setContentText("修改成功！");
            alert.showAndWait();
        }
    }
}
